package com.epro.dx.task;

import android.os.AsyncTask;
import android.text.TextUtils;

import com.epro.dx.listenner.CustomAsyncTaskListener;
import com.weipu.common.constants.Constant;
import com.weipu.common.facade.factory.ProviderFactory;
import com.weipu.common.util.Logger;
import com.weipu.common.util.StringUtil;

/**
 * 获取国家代码和IP的异步任务
 * @author ZengLW
 * @version 1.0
 * @date 2017/7/19
 */
public class GetCountryCodeTask extends AsyncTask<Void,Void,String>{
    private CustomAsyncTaskListener<String> mListener;

    public GetCountryCodeTask(){}

    public GetCountryCodeTask(CustomAsyncTaskListener<String> listener) {
        this.mListener = listener;
    }

    @Override
    protected String doInBackground(Void... params) {

        return ProviderFactory.createIpCountryService().getCountryCode("Region");
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        if (!TextUtils.isEmpty(result)) {
            //保存获取的国家缩写
            StringUtil.saveConfig(Constant.Global.COUNTRY_CODE,result);
            if (null != mListener) {
                mListener.onPostExecute(result);
            }
        }
    }

}
